import { Injectable } from '@angular/core';
import {adSystemApiUrl,tuikeSystemUrl} from "../../../config/api";
import {Headers, RequestOptions} from "@angular/http";
import {HttpService} from "../../lib/service/http.service";

@Injectable()
export class BannerService {

  constructor(private httpService: HttpService) {

  }


  //获取活动列表
  getActivityList(page,pageSize) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/activity_list?page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }

  //获取任务列表
  getTaskList(page,pageSize,type?,orderBy?,taskName?) {
    let url = `${tuikeSystemUrl}/api/v1/admin/Task/task_list?page=${page}&pageSize=${pageSize}&status=0&task_name=${taskName}`;
    orderBy ? url += '&validity_start=' + orderBy['validity_start'] + '&validity_end=' + orderBy['validity_end'] : '';
    type ? url += '&activity_type=' + (type == 1 ? 0 : 5) : '';
    return this.httpService.httpGetAuth(url).map(res => res);
  }


  //活动详情
  getActivityInfo(id) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/activity_info?activity_id=${id}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }

  //新建活动
  addActivity(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/add_activity`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //编辑活动
  editActivity(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/edit_activity`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //删除活动
  deleteActivity(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/delete_activity`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //改变活动状态
  changeStatus(data) {
    const url = `${tuikeSystemUrl}/api/v1/admin/tuike_activity/change_status`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);

  }


}
